package com.jing.mapper;

import com.jing.pojo.ReservationInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 陈书憬
 * @version 1.0
 * 2024/9/20
 */
@Mapper
public interface ReservationInfoMapper {
    //先看座位有没有在数据库中（这个条件是看名称，楼层，区域，类型，座位状态，座位号），
    @Select("select * from reservation_info where name=#{name} and floor=#{floor} and area=#{area} and type=#{type} and reservation_status=#{reservationStatus} and seat_id=#{seatId};")
    void checkSeatAvailability();

    @Insert("insert into reservation_info(name, type, seat_id, floor, area,option_date ,start_time, end_time, check_in_time, check_out_time, user_id,create_time,reservation_status,name_id) VALUES (#{name}, #{type}, #{seatId}, #{floor}, #{area},#{optionDate}, #{startTime}, #{endTime}, #{checkInTime}, #{checkOutTime}, #{userId}, #{createTime},#{reservationStatus},#{nameId})")
    void add(ReservationInfo reservationInfo);

    @Select("SELECT * FROM reservation_info WHERE name_id = #{id} AND seat_id = #{seatId} AND reservation_status IN ('已预约', '进行中');")
    ReservationInfo findSeat(Integer id, Integer seatId);

    @Select("SELECT seat_id FROM reservation_info WHERE name_id = #{id} AND reservation_status IN ('已预约', '进行中');")
    List<Integer> findSeatButton(Integer id);

    @Select("select reservation_status from reservation_info where user_id = #{id};")
    List<String> findUserSeatStatus(Integer id);

    @Select("select * from reservation_info where user_id = #{userId};")
    List<ReservationInfo> findUserMsgById(Integer userId);

    @Update("update reservation_info set check_in_time =#{checkInTime}  where user_id=#{userId};")
    void updateSignIn(Integer userId, String checkInTime);

    @Update("update reservation_info set check_out_time = #{checkOutTime} where user_id=#{userId};")
    void updateSignOut(Integer userId, String checkOutTime);

    @Update("update reservation_info set reservation_status = #{reservationStatus} where user_id=#{userId};")
    void setSeatStatus(Integer userId, String reservationStatus);

    @Delete("delete from reservation_info where user_id=#{userId};")
    void deleteUserInfo(Integer userId);

    @Select("select reservation_status from reservation_info where user_id = #{userId};")
    void selectSeatStatus(Integer userId);

    void changeSeatMsg(ReservationInfo reservationInfo);

//    @Select("SELECT * FROM reservation_info WHERE name_id = #{id} AND seat_id = #{seatId} AND reservation_status IN ('已预约', '进行中');")
    @Select("SELECT * FROM reservation_info WHERE name_id = #{id} AND seat_id = #{seatId} AND reservation_status IN ('已预约', '进行中');")
    List<ReservationInfo> findSeatTimes(Integer id, Integer seatId);

    @Select("select * from reservation_info where option_date=#{nowDate};")
    List<ReservationInfo> selectDatetime(String nowDate);

    @Insert("insert into reservation_info(name, type, seat_id, floor, area,option_date ,start_time, end_time, check_in_time, check_out_time, user_id,create_time,reservation_status,name_id) VALUES (#{name}, #{type}, #{seatId}, #{floor}, #{area},#{optionDate}, #{startTime}, #{endTime}, #{checkInTime}, #{checkOutTime}, #{userId}, #{createTime},#{reservationStatus},#{nameId})")
    void addSensorSeat(ReservationInfo reservationInfo);

//    void addSensorSeat(ReservationInfo reservationInfo);
}
